package pers.zb.cloud.web.upms.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import pers.zb.cloud.web.upms.entity.SysRole;
import pers.zb.cloud.web.upms.entity.SysRoleOperateLog;
import pers.zb.cloud.web.upms.service.hystrix.MenuServiceHystrix;
import pers.zb.cloud.web.upms.service.hystrix.RoleServiceHystrix;
import pers.zb.cloud.web.upms.vo.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "sea-cloud-service-upms", fallback = RoleServiceHystrix.class)
public interface RoleService {

    /**
     * 根据ID获取角色信息
     */
    @RequestMapping(value = "/upms/service/role/{roleId}",method = RequestMethod.GET)
    SysRole getRoleById(@RequestParam("roleId") Long roleId);

    /**
     * 分页获取角色列表
     */
    @RequestMapping(value = "/upms/service/role/page/list",method = RequestMethod.POST)
    Page<SysRole> getRoleListForPage(@RequestBody Map<String,Object> params);

    /**
     * 更新或者添加角色
     */
    @RequestMapping(value = "/upms/service/role/{type}",method = RequestMethod.POST)
    void updateOrSave(@PathVariable("type") int type, @RequestBody SysRole sysRole) throws Exception;

    /**
     * 批量删除角色
     */
    @RequestMapping(value = "/upms/service/role/batch",method = RequestMethod.POST)
    void deleteRole(@RequestParam("roleId") Long[] roleIdArrs) throws Exception;

    /**
     * 分页获取角色操作日志列表
     *      form : 角色管理页面 - 下方的tab选项卡 - 操作日志
     */
    @RequestMapping(value = "/upms/service/role/operatelog/list/page",method = RequestMethod.POST)
    Page<SysRoleOperateLog> getRoleOperateLogForPage(@RequestBody Map<String,Object> params);

    /**
     * 获取角色拥有的权限
     *      from : 角色管理 - 右侧的角色权限tree
     *
     * @param roleId 角色ID
     */
    @RequestMapping(value = "/upms/service/role/operatelog/list/page",method = RequestMethod.POST)
    List<RolePermissionVo> getRolePermissionTreeList(Long roleId);

    /**
     * 获取角色应用授权集合
     *      前端显示为 tree ， 同时每个节点前面显示 checkedbox 选项框。 已经授权的应用的checkedbox为选中状态，反之是未选中状态
     *
     * @param roleId 角色ID
     */
    @RequestMapping(value = "/upms/service/role/authorize/client/list",method = RequestMethod.POST)
    List<RoleClientAuthorizeVo> getRoleClientAuthorizeList(@RequestParam("roleId") Long roleId);

    /**
     * 为角色设置应用的访问权限
     * @param roleId 角色ID
     * @param clientIdArrString 应用的client_id集合，逗号分隔
     */
    @RequestMapping(value = "/upms/service/role/client/authorize/setting",method = RequestMethod.POST)
    void roleClientAuthorize(@RequestParam("roleId") Long roleId, @RequestParam("clientId") String[] clientIdArrString);

    /**
     获取角色拥有应用访问权限的应用列表
     *      from : 角色管理 -> 角色权限设置 -> 角色已授权系统
     *
     * @param roleId 角色ID
     */
    @RequestMapping(value = "/upms/service/role/authorize/client/list/tree",method = RequestMethod.POST)
    List<ClientVo> getRoleClientAuthorizeListTree(@RequestParam("roleId") Long roleId);

    /**
     * 获取角色在应用中的权限
     *
     * @param roleId 角色ID
     * @param clientId 应用的client_id
     * @param permissionId 权限ID
     */
    @RequestMapping(value = "/upms/service/role/client/permission/list/{permissionId}",method = RequestMethod.POST)
    List<RoleClientPermissionVo> getRoleClientPermissionList(@RequestParam("roleId") Long roleId, @RequestParam("clientId") String clientId,@PathVariable("permissionId") Long permissionId);

    /**
     * 为角色设置应用的功能操作权限
     *
     * @param clientId 应用client_id
     * @param roleId 角色ID
     * @param permissionIdArrString 权限ID
     */
    @RequestMapping(value = "/upms/service/role/client/permission/setting",method = RequestMethod.POST)
    void settingRoleClientPermission(@RequestParam("clientId") String clientId, @RequestParam("roleId") Long roleId, @RequestParam("permissionId") Long[] permissionIdArrString);
}
